package com.ocom.payconfig.controller;

import com.ocom.common.constant.PayConfigUrl;
import com.ocom.common.entity.master.EntityWechatAppInfo;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.resp.Result;
import com.ocom.common.utils.CommonUtil;
import com.ocom.common.utils.ResultUtil;
import com.ocom.payconfig.service.WechatAppInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: TODO
 * @Author: 朱晖
 * @Date: 2022/7/18
 **/
@RestController
public class WechatAppInfoController {

	@Autowired
	WechatAppInfoService wechatAppInfoService;


	@Deprecated
	@PostMapping(PayConfigUrl.URLP_addWxInfo)
	public Result addWxInfo(@RequestBody EntityWechatAppInfo entityWechatAppInfo){
		Boolean b = wechatAppInfoService.addInfo(entityWechatAppInfo);
		if(!b){
			return ResultUtil.error(ResultEnum.Err_3043);
		}
		return ResultUtil.success();
	}


	@PostMapping(PayConfigUrl.URLP_getWxInfo)
	public Result<EntityWechatAppInfo> getWxInfo(@RequestParam("comId") Long comId ,
							@RequestParam("merchId")  Long merchId,
							@RequestParam(value = "appName",required = false,defaultValue = "gzh")  String appName){
		if(CommonUtil.isNull(appName)){
			appName="gzh";
		}
		EntityWechatAppInfo entityWechatAppInfo = wechatAppInfoService.getInfo(comId,merchId,appName);
		if(entityWechatAppInfo==null){
			return ResultUtil.error(ResultEnum.Err_3044);
		}
		return ResultUtil.success(entityWechatAppInfo);
	}


}
